package com.kyzh.core.adapters

import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.RelativeLayout
import androidx.viewpager.widget.PagerAdapter
import com.kyzh.core.R

class LaunchAdapter(val context: Context) : PagerAdapter() {

    override fun getCount(): Int {
        return 3
    }

    override fun instantiateItem(container: ViewGroup, position: Int): Any {
        val view = View.inflate(context, R.layout.launch_item,null)

        val list1 = arrayListOf(R.drawable.launch_title1,R.drawable.launch_mid1,R.drawable.launch_light1,R.drawable.launch_bg1)
        val list2 = arrayListOf(R.drawable.launch_title2,R.drawable.launch_mid2,R.drawable.launch_light2,R.drawable.launch_bg2)
        val list3 = arrayListOf(R.drawable.launch_title3,R.drawable.launch_mid3,R.drawable.launch_light3,R.drawable.launch_bg3)
        val beans = arrayListOf(list1,list2,list3)
        val root1 = view.findViewById<ImageView>(R.id.imageview1)
        val root2 = view.findViewById<ImageView>(R.id.imageview2)
        val root3 = view.findViewById<ImageView>(R.id.imageview3)
        val root4 = view.findViewById<RelativeLayout>(R.id.root)
        root1.setImageResource(beans[position][0])
        root2.setImageResource(beans[position][1])
        root3.setImageResource(beans[position][2])
        root4.setBackgroundResource(beans[position][3])
        container.addView(view)
        return view
    }
    override fun isViewFromObject(view: View, `object`: Any): Boolean {
        return view ==`object`
    }

    override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
        container.removeView(`object`as View)
    }
}

